package com.newcoder.controller;


import com.newcoder.event.EventProducer;
import com.newcoder.service.impl.LikeServiceImpl;
import com.newcoder.util.CommunityConstant;
import com.newcoder.util.HostHolder;
import com.newcoder.util.ResponseWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/like")
public class LikeController implements CommunityConstant {

    @Autowired
    private LikeServiceImpl likeService;

    @Autowired
    private HostHolder hostHolder;

    @Autowired
    private EventProducer eventProducer;

    @Autowired
    private RedisTemplate redisTemplate;


    @ApiOperation("点赞")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entityType",value = "类型"),
            @ApiImplicitParam(name = "entityId",value = "id"),
            @ApiImplicitParam(name = "entityUserId",value = "拥有者id"),
            @ApiImplicitParam(name = "postId",value = "操作者id"),
    })
    @PostMapping("/likeMethod")
    public ResponseWrapper like(@RequestParam(name = "id")int userId,
                                @RequestParam(name = "entityType")int entityType,
                                @RequestParam(name = "entityId")int entityId,
                                @RequestParam(name = "entityUserId")int entityUserId,
                                @RequestParam(name = "postId")int postId) {
        ResponseWrapper wrapper = likeService.like(userId, entityType, entityId, entityUserId, postId);
        return wrapper;
    }

}
